<template><div><h2 id="安装docker-ubuntu22" tabindex="-1"><a class="header-anchor" href="#安装docker-ubuntu22"><span>安装docker（ubuntu22)</span></a></h2>
<blockquote>
<p><a href="https://gt2kk.cn/blog/ubuntu/2025-05-30-ubuntu-docker" target="_blank" rel="noopener noreferrer">Ubuntu 24.04 安装 Docker 并配置国内镜像源（适用于中国服务器） | Aldrin-Blog</a></p>
</blockquote>
<div class="language-bash line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="bash" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic"># 卸载老版本</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> remove</span><span style="color:#98C379"> docker</span><span style="color:#98C379"> docker-engine</span><span style="color:#98C379"> docker.io</span><span style="color:#98C379"> containerd</span><span style="color:#98C379"> runc</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 更新apt包索引</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> update</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 安装必要工具包</span></span>
<span class="line"><span style="color:#61AFEF"> sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> install</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">    apt-transport-https</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">    ca-certificates</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">    curl</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">    gnupg-agent</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">    software-properties-common</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 添加Docker GPG秘钥</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 1. 默认使用国外源，非常非常非常慢！</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> curl</span><span style="color:#D19A66"> -fsSL</span><span style="color:#98C379"> https://download.docker.com/linux/ubuntu/gpg</span><span style="color:#ABB2BF"> | </span><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-key</span><span style="color:#98C379"> add</span><span style="color:#98C379"> -</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 2. 推荐使用国内源，顺畅！</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> curl</span><span style="color:#D19A66"> -fsSL</span><span style="color:#98C379"> https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg</span><span style="color:#ABB2BF"> | </span><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-key</span><span style="color:#98C379"> add</span><span style="color:#98C379"> -</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 配置仓库源</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 1. 默认使用国外源，非常非常非常慢！</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> add-apt-repository</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">       "deb [arch=amd64] https://download.docker.com/linux/ubuntu </span><span style="color:#56B6C2">\</span></span>
<span class="line"><span style="color:#98C379">       $(</span><span style="color:#61AFEF">lsb_release</span><span style="color:#D19A66"> -cs</span><span style="color:#98C379">) </span><span style="color:#56B6C2">\</span></span>
<span class="line"><span style="color:#98C379">       stable"</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 2. 推荐使用国内源，顺畅！</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> add-apt-repository</span><span style="color:#56B6C2"> \</span></span>
<span class="line"><span style="color:#98C379">      "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu </span><span style="color:#56B6C2">\</span></span>
<span class="line"><span style="color:#98C379">      $(</span><span style="color:#61AFEF">lsb_release</span><span style="color:#D19A66"> -cs</span><span style="color:#98C379">) </span><span style="color:#56B6C2">\</span></span>
<span class="line"><span style="color:#98C379">      stable"</span><span style="color:#ABB2BF">	</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 安装Docker </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 更新apt包索引</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> update</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 安装docker</span></span>
<span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> install</span><span style="color:#98C379"> docker-ce</span><span style="color:#98C379"> docker-ce-cli</span><span style="color:#98C379"> containerd.io</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 启动docker</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 设置开机自启</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> systemctl</span><span style="color:#98C379"> enable</span><span style="color:#98C379"> docker</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> systemctl</span><span style="color:#98C379"> start</span><span style="color:#98C379"> docker</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h3 id="docker-hub换源" tabindex="-1"><a class="header-anchor" href="#docker-hub换源"><span>docker-hub换源</span></a></h3>
<p>因为要去docker-hub拉去镜像，所以我们一般更换国内的docker-hub仓库加快拉取镜像速度</p>
<div class="language-bash line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="bash" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> mkdir</span><span style="color:#D19A66"> -p</span><span style="color:#98C379"> /etc/docker</span><span style="color:#7F848E;font-style:italic"> # “-p”，执行此命令会先检查目录是否存在。若不存在，则创建相应目录；否则，不执行任何操作。因此不管是否有该目录，直接执行此命令都没问题，不会报错。</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> vi</span><span style="color:#98C379"> /etc/docker/daemon.json</span><span style="color:#7F848E;font-style:italic"> # 如果没有会自动创建</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 往里粘入以下内容</span></span>
<span class="line"><span style="color:#ABB2BF">{</span></span>
<span class="line"><span style="color:#61AFEF">    "registry-mirrors"</span><span style="color:#56B6C2">:</span><span style="color:#ABB2BF"> [</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker.m.daocloud.io"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker.imgdb.de"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker-0.unsee.tech"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker.hlmirror.com"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker.1ms.run"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://func.ink"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://lispy.org"</span><span style="color:#61AFEF">,</span></span>
<span class="line"><span style="color:#61AFEF">    	"https://docker.xiaogenban1993.com"</span></span>
<span class="line"><span style="color:#ABB2BF">    ]</span></span>
<span class="line"><span style="color:#ABB2BF">}</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 重启docker服务</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> systemctl</span><span style="color:#98C379"> daemon-reload</span><span style="color:#ABB2BF"> &#x26;&#x26; </span><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> systemctl</span><span style="color:#98C379"> restart</span><span style="color:#98C379"> docker</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h3 id="docke常用命令" tabindex="-1"><a class="header-anchor" href="#docke常用命令"><span>docke常用命令</span></a></h3>
<div class="language-bash line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="bash" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 查看所有的容器</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> ps</span><span style="color:#7F848E;font-style:italic"> # 查看所有存活的容器</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> ps</span><span style="color:#D19A66"> -a</span><span style="color:#7F848E;font-style:italic"> # 查看所有的容器，无论是否存活</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 查看所有镜像</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> images</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 删除镜像</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> rmi</span><span style="color:#98C379"> id前三位</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 停止容器</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> stop</span><span style="color:#98C379"> id前三位</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 删除容器前三位</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> rm</span><span style="color:#98C379"> id前三位</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># docker进入容器</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 这种方式进入不会开启新的终端</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 如果使用exit命令退出则会停止容器</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 如果想退出容器但不想容器停止，则按住Ctrl+P+Q退出</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> attach</span><span style="color:#98C379"> 容器id/容器name</span><span style="color:#ABB2BF"> </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 这种方式进入则会开启新的终端</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 使用exit命令退出不会停止容器</span></span>
<span class="line"><span style="color:#61AFEF">docker</span><span style="color:#98C379"> exec</span><span style="color:#D19A66"> -it</span><span style="color:#98C379"> 容器id/容器name</span><span style="color:#98C379"> /bin/bash</span><span style="color:#7F848E;font-style:italic"> #/容器内路径</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h2 id="安装docker-compose" tabindex="-1"><a class="header-anchor" href="#安装docker-compose"><span>安装docker-compose</span></a></h2>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">$</span><span style="color:#98C379"> sudo</span><span style="color:#98C379"> curl</span><span style="color:#D19A66"> -L</span><span style="color:#98C379"> "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(</span><span style="color:#61AFEF">uname</span><span style="color:#D19A66"> -s</span><span style="color:#98C379">)-$(</span><span style="color:#61AFEF">uname</span><span style="color:#D19A66"> -m</span><span style="color:#98C379">)"</span><span style="color:#D19A66"> -o</span><span style="color:#98C379"> /usr/local/bin/docker-compose</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> chmod</span><span style="color:#98C379"> +x</span><span style="color:#98C379"> /usr/local/bin/docker-compose</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="创建目录" tabindex="-1"><a class="header-anchor" href="#创建目录"><span>创建目录</span></a></h2>
<p>个人习惯将/home/project/项目名 作为工作目录</p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">tree</span><span style="color:#98C379"> .</span><span style="color:#7F848E;font-style:italic"> # 使用tree命令打印层次结构</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> conf</span><span style="color:#7F848E;font-style:italic"> # 配置文件夹</span></span>
<span class="line"><span style="color:#61AFEF">│</span><span style="color:#98C379">   ├──</span><span style="color:#98C379"> nginx.conf</span><span style="color:#7F848E;font-style:italic"> # nginx配置文件</span></span>
<span class="line"><span style="color:#61AFEF">│</span><span style="color:#98C379">   └──</span><span style="color:#98C379"> redis.conf</span><span style="color:#7F848E;font-style:italic"> # redis配置文件</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> db</span><span style="color:#7F848E;font-style:italic"> # 数据库建表sql以及其他的sql存放文件夹</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> docker-compose.yml</span><span style="color:#7F848E;font-style:italic"> # docker-compose配置文件</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> html</span><span style="color:#7F848E;font-style:italic"> # 前端代码文件夹</span></span>
<span class="line"><span style="color:#61AFEF">│</span><span style="color:#98C379">   └──</span><span style="color:#98C379"> dist</span><span style="color:#7F848E;font-style:italic"> # 前端打包代码</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> jar</span><span style="color:#7F848E;font-style:italic"> # 后端jar包存放文件夹</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> nginx-dockerfile</span><span style="color:#7F848E;font-style:italic"> # nginx容器dockerfile</span></span>
<span class="line"><span style="color:#61AFEF">├──</span><span style="color:#98C379"> redis-dockerfile</span><span style="color:#7F848E;font-style:italic"> # redis容器dockerfile</span></span>
<span class="line"><span style="color:#61AFEF">└──</span><span style="color:#98C379"> backend-dockerfile</span><span style="color:#7F848E;font-style:italic"> # 后端容器dockerfile</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> mkdir</span><span style="color:#D19A66"> -p</span><span style="color:#98C379"> conf</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> mkdir</span><span style="color:#D19A66"> -p</span><span style="color:#98C379"> db</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> mkdir</span><span style="color:#D19A66"> -p</span><span style="color:#98C379"> html</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> mkdir</span><span style="color:#D19A66"> -p</span><span style="color:#98C379"> jar</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="nginx部署" tabindex="-1"><a class="header-anchor" href="#nginx部署"><span>nginx部署</span></a></h2>
<p><strong>demo</strong></p>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span># 基础镜像</span></span>
<span class="line"><span>FROM nginx</span></span>
<span class="line"><span># author</span></span>
<span class="line"><span>MAINTAINER ruoyi</span></span>
<span class="line"><span># 挂载目录</span></span>
<span class="line"><span>VOLUME /home/ruoyi/projects/ruoyi-ui</span></span>
<span class="line"><span># 创建目录</span></span>
<span class="line"><span>RUN mkdir -p /home/ruoyi/projects/ruoyi-ui</span></span>
<span class="line"><span># 指定路径</span></span>
<span class="line"><span>WORKDIR /home/ruoyi/projects/ruoyi-ui</span></span>
<span class="line"><span># 复制conf文件到路径</span></span>
<span class="line"><span>COPY ./conf/nginx.conf /etc/nginx/nginx.conf</span></span>
<span class="line"><span># 复制html文件到路径</span></span>
<span class="line"><span>COPY ./html/dist /home/ruoyi/projects/ruoyi-ui</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="后端部署" tabindex="-1"><a class="header-anchor" href="#后端部署"><span>后端部署</span></a></h2>
<p><strong>后端打包</strong></p>
<p>检查springboot自带的插件是否设置正确（尤其是主类和ar包）</p>
<div class="language-xml line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="xml" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#ABB2BF">&#x3C;</span><span style="color:#E06C75">plugin</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;</span><span style="color:#E06C75">groupId</span><span style="color:#ABB2BF">>org.springframework.boot&#x3C;/</span><span style="color:#E06C75">groupId</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;</span><span style="color:#E06C75">artifactId</span><span style="color:#ABB2BF">>spring-boot-maven-plugin&#x3C;/</span><span style="color:#E06C75">artifactId</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;</span><span style="color:#E06C75">version</span><span style="color:#ABB2BF">>${spring-boot.version}&#x3C;/</span><span style="color:#E06C75">version</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;</span><span style="color:#E06C75">configuration</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">        &#x3C;</span><span style="color:#E06C75">mainClass</span><span style="color:#ABB2BF">>xyz.hmz.backend.BackendApplication&#x3C;/</span><span style="color:#E06C75">mainClass</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">        &#x3C;</span><span style="color:#E06C75">skip</span><span style="color:#ABB2BF">>false&#x3C;/</span><span style="color:#E06C75">skip</span><span style="color:#ABB2BF">> </span><span style="color:#7F848E;font-style:italic">&#x3C;!-- 打包 将外部jar包打包进项目中 --></span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">        &#x3C;!-- &#x3C;includeSystemScope>true&#x3C;/includeSystemScope>  &#x26;lt;!&#x26;ndash; 如果报错，请解除这句话的注释 &#x26;ndash;&#x26;gt;--></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;/</span><span style="color:#E06C75">configuration</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;</span><span style="color:#E06C75">executions</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">        &#x3C;</span><span style="color:#E06C75">execution</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">            &#x3C;</span><span style="color:#E06C75">id</span><span style="color:#ABB2BF">>repackage&#x3C;/</span><span style="color:#E06C75">id</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">            &#x3C;</span><span style="color:#E06C75">goals</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">                &#x3C;</span><span style="color:#E06C75">goal</span><span style="color:#ABB2BF">>repackage&#x3C;/</span><span style="color:#E06C75">goal</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">            &#x3C;/</span><span style="color:#E06C75">goals</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">        &#x3C;/</span><span style="color:#E06C75">execution</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">    &#x3C;/</span><span style="color:#E06C75">executions</span><span style="color:#ABB2BF">></span></span>
<span class="line"><span style="color:#ABB2BF">&#x3C;/</span><span style="color:#E06C75">plugin</span><span style="color:#ABB2BF">></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><p><strong>backend-dockerfile</strong></p>
<div class="language- line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span># 基础镜像</span></span>
<span class="line"><span># FROM openjdk:17</span></span>
<span class="line"><span>FROM azul/zulu-openjdk-alpine:17.0.14</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 使用 LABEL 替代 MAINTAINER 来添加作者信息</span></span>
<span class="line"><span>LABEL maintainer="hmz"</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 创建目录</span></span>
<span class="line"><span>RUN mkdir -p /project/library-system</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 复制jar文件到容器内某路径</span></span>
<span class="line"><span>COPY ./jar/*.jar /project/library-system/backend.jar</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 指定路径</span></span>
<span class="line"><span>WORKDIR /project/library-system</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 挂载目录</span></span>
<span class="line"><span>VOLUME /project/library-system</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 启动应用</span></span>
<span class="line"><span>ENTRYPOINT ["java", "-jar", "backend.jar"]</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h2 id="redis部署" tabindex="-1"><a class="header-anchor" href="#redis部署"><span>redis部署</span></a></h2>
<p><strong>demo</strong></p>
<div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span># 基础镜像</span></span>
<span class="line"><span>FROM redis</span></span>
<span class="line"><span># author</span></span>
<span class="line"><span>MAINTAINER ruoyi</span></span>
<span class="line"><span># 挂载目录</span></span>
<span class="line"><span>VOLUME /home/ruoyi/redis</span></span>
<span class="line"><span># 创建目录</span></span>
<span class="line"><span>RUN mkdir -p /home/ruoyi/redis</span></span>
<span class="line"><span># 指定路径</span></span>
<span class="line"><span>WORKDIR /home/ruoyi/redis</span></span>
<span class="line"><span># 复制conf文件到路径</span></span>
<span class="line"><span>COPY ./conf/redis.conf /home/ruoyi/redis/redis.conf</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="编写docker-compose" tabindex="-1"><a class="header-anchor" href="#编写docker-compose"><span>编写docker-compose</span></a></h2>
<p><strong>demo</strong></p>
<div class="language-yml line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="yml" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">version</span><span style="color:#ABB2BF"> : </span><span style="color:#98C379">'3'</span></span>
<span class="line"><span style="color:#E06C75">services</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">  ruoyi-mysql</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">    container_name</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">ruoyi-mysql</span></span>
<span class="line"><span style="color:#E06C75">    image</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">mysql:5.7</span></span>
<span class="line"><span style="color:#E06C75">    build</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">      context</span><span style="color:#ABB2BF">: </span><span style="color:#D19A66">.</span></span>
<span class="line"><span style="color:#E06C75">      dockerfile</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">mysql-dockerfile</span></span>
<span class="line"><span style="color:#E06C75">    ports</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">"3306:3306"</span></span>
<span class="line"><span style="color:#E06C75">    volumes</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./mysql/conf:/etc/mysql/conf.d</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./mysql/logs:/logs</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./mysql/data:/var/lib/mysql</span></span>
<span class="line"><span style="color:#E06C75">    command</span><span style="color:#ABB2BF">: [</span></span>
<span class="line"><span style="color:#98C379">          'mysqld'</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">          '--innodb-buffer-pool-size=80M'</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">          '--character-set-server=utf8mb4'</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">          '--collation-server=utf8mb4_unicode_ci'</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">          '--default-time-zone=+8:00'</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">          '--lower-case-table-names=1'</span></span>
<span class="line"><span style="color:#ABB2BF">        ]</span></span>
<span class="line"><span style="color:#E06C75">    environment</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">      MYSQL_DATABASE</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">'ry-vue'</span></span>
<span class="line"><span style="color:#E06C75">      MYSQL_ROOT_PASSWORD</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">zhangyin</span><span style="color:#7F848E;font-style:italic">  #数据库root用户密码</span></span>
<span class="line"><span style="color:#E06C75">  ruoyi-redis</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">    container_name</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">ruoyi-redis</span></span>
<span class="line"><span style="color:#E06C75">    image</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">redis</span></span>
<span class="line"><span style="color:#E06C75">    build</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">      context</span><span style="color:#ABB2BF">: </span><span style="color:#D19A66">.</span></span>
<span class="line"><span style="color:#E06C75">      dockerfile</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">redis-dockerfile</span></span>
<span class="line"><span style="color:#E06C75">    ports</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">"6379:6379"</span></span>
<span class="line"><span style="color:#E06C75">    volumes</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./conf/redis.conf:/home/ruoyi/redis/redis.conf</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./redis/data:/data</span></span>
<span class="line"><span style="color:#E06C75">    command</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">redis-server /home/ruoyi/redis/redis.conf</span></span>
<span class="line"><span style="color:#E06C75">  ruoyi-nginx</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">    container_name</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">ruoyi-nginx</span></span>
<span class="line"><span style="color:#E06C75">    image</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">nginx</span></span>
<span class="line"><span style="color:#E06C75">    build</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">      context</span><span style="color:#ABB2BF">: </span><span style="color:#D19A66">.</span></span>
<span class="line"><span style="color:#E06C75">      dockerfile</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">nginx-dockerfile</span></span>
<span class="line"><span style="color:#E06C75">    ports</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">"80:80"</span></span>
<span class="line"><span style="color:#E06C75">    volumes</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./html/dist:/home/ruoyi/projects/ruoyi-ui</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./conf/nginx.conf:/etc/nginx/nginx.conf</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./nginx/logs:/var/log/nginx</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./nginx/conf.d:/etc/nginx/conf.d</span></span>
<span class="line"><span style="color:#E06C75">    depends_on</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-server</span></span>
<span class="line"><span style="color:#E06C75">    links</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-server</span></span>
<span class="line"><span style="color:#E06C75">  ruoyi-server</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">    container_name</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">ruoyi-server</span></span>
<span class="line"><span style="color:#E06C75">    build</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#E06C75">      context</span><span style="color:#ABB2BF">: </span><span style="color:#D19A66">.</span></span>
<span class="line"><span style="color:#E06C75">      dockerfile</span><span style="color:#ABB2BF">: </span><span style="color:#98C379">ruoyi-dockerfile</span></span>
<span class="line"><span style="color:#E06C75">    ports</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">"8080:8080"</span></span>
<span class="line"><span style="color:#E06C75">    volumes</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./ruoyi/logs:/home/ruoyi/logs</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">./ruoyi/uploadPath:/home/ruoyi/uploadPath</span></span>
<span class="line"><span style="color:#E06C75">    depends_on</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-mysql</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-redis</span></span>
<span class="line"><span style="color:#E06C75">    links</span><span style="color:#ABB2BF">:</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-mysql</span></span>
<span class="line"><span style="color:#ABB2BF">      - </span><span style="color:#98C379">ruoyi-redis</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic"># 构建docker服务</span></span>
<span class="line"><span style="color:#61AFEF">docker-compose</span><span style="color:#98C379"> build</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 启动docker服务</span></span>
<span class="line"><span style="color:#61AFEF">docker-compose</span><span style="color:#98C379"> up</span><span style="color:#7F848E;font-style:italic"> # 后面加 -d 不进入容器</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div></template>


